﻿Imports Newtonsoft.Json.Linq
Imports System.Net
Imports System.IO

Public Class clsFriendCount
    Dim frm As frmMain
    Dim info As objInfoLogin

    Public Sub New(ByRef frmMain As frmMain, ByRef infoLogin As objInfoLogin)
        frm = frmMain
        info = infoLogin
    End Sub

    Public Sub get_count()
        frm.FriendFB.isCheckFriendCount = True
        Dim request As HttpWebRequest
        Dim response As HttpWebResponse = Nothing
        Dim reader As StreamReader
        Try
            Debug.Print(info.FacebookID)
            request = DirectCast(WebRequest.Create("https://graph.facebook.com/fql?q=SELECT%20friend_count%20FROM%20user%20WHERE%20uid%20=" & info.FacebookID), HttpWebRequest)
            response = DirectCast(request.GetResponse(), HttpWebResponse)
            reader = New StreamReader(response.GetResponseStream())

            Dim rawresp As String
            rawresp = reader.ReadToEnd()
            If rawresp <> "" Then
                Debug.Print(rawresp)
                Dim json As JObject = JObject.Parse(rawresp)
                Debug.Print(json.SelectToken("data")(0).SelectToken("friend_count"))
                frm.lblTotalFriend.Text = json.SelectToken("data")(0).SelectToken("friend_count")
            End If


        Catch ex As Exception

        Finally

        End Try
        frm.FriendFB.isCheckFriendCount = False
    End Sub
End Class
